#include<bits/stdc++.h>
using namespace std;
const int N=100010;
int T,n,m,l,v,ans1,ans2;
struct car{
    int d,v,a;
}ca[N];
int p[N];
int f[N];
bool cmp1(car a,car b)
{
    if(a.d!=b.d) return a.d>b.d;
}
bool cmp2(int a,int b)
{
    if(a!=b) return a>b;
}
void solveC()
{
    ans1=0;
    for(int i=1;i<=n;i++)
    {
        if(ca[i].d<=p[1]&&ca[i].v>v) ans1++;
    }
    cout<<ans1<<' ';
    if(ans1==0) cout<<m<<'\n';
    else cout<<m-1<<'\n';
}
void solveB()
{
    for(int i=1;i<=n;i++)
    {
        double x;
        if(ca[i].v>v) continue;
        else
        {
            ca[i].d+=int(double((v*v*-ca[i].v*ca[i].v)*1.0)/double((2*ca[i].a*1.0)));
            ca[i].v=v+1;
        }
    }
    solveC();
}
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--)
    {
        cin>>n>>m>>l>>v;
        bool flag1=0,flag2=0,flag3=0;
        memset(ca,0,sizeof(ca));
        memset(p,0,sizeof(p));
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d%d",&ca[i].d,&ca[i].v,&ca[i].a);
            if(ca[i].a!=0) flag1=1;
            if(ca[i].a<0) flag2=1;
            if(ca[i].a>0) flag3=1;
        }
        for(int i=1;i<=m;i++)
            scanf("%d",&p[i]);
        sort(ca+1,ca+n+1,cmp1);
        sort(p+1,p+m+1,cmp2);
        if(flag1==0) solveC();
        else if(flag2==0) solveB();
    }
    return 0;
}
